package com.gaswell.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaswell.pojo.RtuData;
import com.gaswell.vo.FindLastDataVo2;
import com.gaswell.vo.FindLastDataVo2_1;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface RtuDataMapper extends EasyBaseMapper<RtuData> {

    @Select("select cjsj,${properties} FROM rtu_data_qj where DATE_FORMAT( cjsj, '%Y-%m-%d %h:%i:%s')>#{down} AND DATE_FORMAT( cjsj, '%Y-%m-%d %h:%i:%s')<#{up} and jh=#{ywbh}")
    List<Map<String, String>> selectData(@Param("down") String down, @Param("up") String up, @Param("properties") String properties, @Param("ywbh") String ywbh);

    @Select("select cjsj,${properties} as ytyc FROM rtu_data_qj where DATE_FORMAT( cjsj, '%Y-%m-%d %h:%i:%s')>#{down} AND DATE_FORMAT( cjsj, '%Y-%m-%d %h:%i:%s')<#{up} and jh=#{ywbh}")
    List<Map<String, String>> selectDataYtyc(@Param("down") String down, @Param("up") String up, @Param("properties") String properties, @Param("ywbh") String ywbh);

    @Select("select DISTINCT jh from rtu_data_qj ")
    List<String> selectAllJh();

    @Select("select jh,cjsj,J_YGYL AS YGYL,J_TGYL AS TGYL,J_ZQYL AS ZQYL,J_YGWD AS YGWD,J_WSWD AS WSWD,J_FCS AS FCS,J_FOS AS FOS,J_VVC AS VVC,Z_JZWD AS JZWD,Z_SJHWD AS SJHWD,Z_JRHWD AS JRHWD,Z_JZYL AS JZYL,Z_SJHYL AS SJHYL from rtu_data_qj where jh=#{jh} order by cjsj desc LIMIT 1")
    RtuData findLatestData(@Param("jh") String jh);


    //    @Select(" select r4.*,q1.scq,q1.ym,q1.zm,q1.ywbh,q1.zwbh " +
//            "from (select r1.jh,r1.cjsj,r1.J_YGYL AS YL,r1.J_TGYL AS TL,r1.J_ZQYL AS ZQYL,r1.J_YGWD AS JKWD,r1.J_WSWD AS WSWD,r1.J_FCS AS FCS,r1.J_FOS AS FOS,r1.J_VVC AS VVC,r1.Z_JZWD AS JZWD,r1.Z_SJHWD AS SJHWD,r1.Z_JRHWD AS JRHWD,r1.Z_JZYL AS JZYL,r1.Z_SJHYL AS SJHYL from gaswell_rtu.rtu_data_qj r1 " +
//            "inner join (select r2.jh as jh, max(r2.cjsj) as cjsj from gaswell_rtu.rtu_data_qj r2 group by jh) r3  on r1.jh=r3.jh and r1.cjsj=r3.cjsj) r4 " +
//            "left join gaswell.allqj q1 on q1.ywbh=r4.jh or q1.zwbh = r4.jh ")
//    @Select("select jh,cjsj,J_YGYL AS YGYL,J_TGYL AS TGYL,J_ZQYL AS ZQYL,J_YGWD AS YGWD,J_WSWD AS WSWD,J_FCS AS FCS,J_FOS AS FOS,J_VVC AS VVC,Z_JZWD AS JZWD,Z_SJHWD AS SJHWD,Z_JRHWD AS JRHWD,Z_JZYL AS JZYL,Z_SJHYL AS SJHYL from rtu_data_qj where jh in #{jhs} order by cjsj desc LIMIT 1")
//    @Select("select r1.jh,r1.cjsj,r1.J_YGYL AS YGYL,r1.J_TGYL AS TGYL,r1.J_ZQYL AS ZQYL,r1.J_YGWD AS YGWD,r1.J_WSWD AS WSWD,r1.J_FCS AS FCS,r1.J_FOS AS FOS,r1.J_VVC AS VVC,r1.Z_JZWD AS JZWD,r1.Z_SJHWD AS SJHWD,r1.Z_JRHWD AS JRHWD,r1.Z_JZYL AS JZYL,r1.Z_SJHYL AS SJHYL " +
//            "from rtu_data_qj r1 inner join (select r2.jh as jh, max(r2.cjsj) as cjsj from rtu_data_qj r2 group by jh) r3  on r1.jh=r3.jh and r1.cjsj=r3.cjsj where r1.jh in #{jhs1} or r1.jh in #{jhs2};")
    List<FindLastDataVo2> findLatestData2(@Param("jhs1") List<String> jhs1, @Param("jhs2") List<String> jhs2);


    //查询时间段的内容
//    @Select(" select r4.*,q1.scq,q1.ym,q1.zm,q1.ywbh,q1.zwbh " +
//            "from (select r1.jh,r1.cjsj,r1.J_YGYL AS YL,r1.J_TGYL AS TL,r1.J_ZQYL AS ZQYL,r1.J_YGWD AS JKWD,r1.J_WSWD AS WSWD,r1.J_FCS AS FCS,r1.J_FOS AS FOS,r1.J_VVC AS VVC,r1.Z_JZWD AS JZWD,r1.Z_SJHWD AS SJHWD,r1.Z_JRHWD AS JRHWD,r1.Z_JZYL AS JZYL,r1.Z_SJHYL AS SJHYL from gaswell_rtu.rtu_data_qj r1 " +
//            "where DATE_FORMAT(r1.cjsj, '%Y-%m-%d %h:%i:%s')>=#{start} and DATE_FORMAT(r1.cjsj, '%Y-%m-%d %h:%i:%s')<=#{end}) r4 " +
//            "left join gaswell.allqj q1 on q1.ywbh=r4.jh or q1.zwbh = r4.jh ")
//    @Select("select jh,cjsj,J_YGYL AS YGYL,J_TGYL AS TGYL,J_ZQYL AS ZQYL,J_YGWD AS YGWD,J_WSWD AS WSWD,J_FCS AS FCS,J_FOS AS FOS,J_VVC AS VVC,Z_JZWD AS JZWD,Z_SJHWD AS SJHWD,Z_JRHWD AS JRHWD,Z_JZYL AS JZYL,Z_SJHYL AS SJHYL from rtu_data_qj where jh in #{jhs} order by cjsj desc LIMIT 1")
//    @Select("select r1.jh,r1.cjsj,r1.J_YGYL AS YGYL,r1.J_TGYL AS TGYL,r1.J_ZQYL AS ZQYL,r1.J_YGWD AS YGWD,r1.J_WSWD AS WSWD,r1.J_FCS AS FCS,r1.J_FOS AS FOS,r1.J_VVC AS VVC,r1.Z_JZWD AS JZWD,r1.Z_SJHWD AS SJHWD,r1.Z_JRHWD AS JRHWD,r1.Z_JZYL AS JZYL,r1.Z_SJHYL AS SJHYL " +
//            "from rtu_data_qj r1 inner join (select r2.jh as jh, max(r2.cjsj) as cjsj from rtu_data_qj r2 group by jh) r3  on r1.jh=r3.jh and r1.cjsj=r3.cjsj where r1.jh in #{jhs1} or r1.jh in #{jhs2};")
    Page<FindLastDataVo2> findLatestDataPeriod(Page<FindLastDataVo2> rowPage, @Param("jhs1") List<String> jhs1, @Param("jhs2") List<String> jhs2, @Param("start") String start, @Param("end") String end);


    Page<RtuData> selectByMutiOptions(Page<RtuData> rowPage, @Param("up") String up, @Param("down") String down, @Param("sort") Integer sort, @Param("jhs") List<String> jhs, @Param("ym") String ym);


    Page<RtuData> selectByMutiOptionsByAllJh(Page<RtuData> rowPage, @Param("up") String up, @Param("down") String down, @Param("sort") Integer sort, @Param("zwbhs") List<String> zwbhs, @Param("ywbhs") List<String> ywbhs, @Param("ym") String ym);
}
